<template>
  <div id="app">
      <van-image width="100%"  height="210" :src="info.qyimg" class="gqimg" />
      <div class="kt-cont">
        <div v-html="about.content"></div>
      </div>
      <div class="h-30"></div>
      <div class="h-20"></div>
      <div id="pad-ws">
        <p class="VIP-title">VIP 会员</p>
        <p class="vip-money"><span class="vip-money-span">￥</span>{{info.vipmoney}}<span class="vip-money-span">元</span></p>
      </div>
      <div class="h-20"></div>
      <van-button class="btn" block color="linear-gradient(to right, #f8c897, #b27b45)" round @click="zhifu">   立即开通，尽享权益</van-button>
      <div class="h-20"></div>
      <div id="pad-ws">
        <van-checkbox  class="about-xx" v-model="checked" checked-color="#bf8d5e" shape="square">我已阅读并同意<router-link :to="'/about?id=15'">《 用户协议 》</router-link></van-checkbox>
      </div>
  </div>
</template>
<script>
  import Vue from 'vue';
  import { Toast } from 'vant';
export default {
  data () {
    return {
      info:[],
      id:'',
      about:[],
      checked: false,
    }
  },
  components: {
  },
  created:function () {
    this.$emit('footer', false);
  },

  mounted () {
    this.recordapi();
  },
  	methods: {
      zhifu(){
        var that= this;
        var userid = this.$cookieStore.getCookie('userid');
        var money = that.value;
        if(that.checked == false){
           this.$toast('请勾选协议');
          return;
        }
        console.log(money)
        that.$api.post("/member/moneysave",{'userid':userid,'money':money}).then(res => {
          // if(res.code==1){
          //   Toast(res.msg);
          //   that.list = [];
          //   that.page = 1;
          //   this.asideData();
          // }else{
          //   Toast(res.msg);
          // }
           that.callpay(res);
            console.log(res);
            console.log(this);
        })
      },

      callpay: function(result) {
          let that = this;
          if (typeof WeixinJSBridge == "undefined") {
              if (document.addEventListener) {
                  document.addEventListener("WeixinJSBridgeReady",that.jsApiCall(result),false);
              } else if (document.attachEvent) {
                  document.attachEvent("WeixinJSBridgeReady",that.jsApiCall(result));
                  document.attachEvent("onWeixinJSBridgeReady",that.jsApiCall(result));
              }
          } else {
              that.jsApiCall(result);
          }
      },
      jsApiCall:function(result) {
        let that = this;
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest',{
            "appId":result.config.appId,           //公众号名称，由商户传入
            "timeStamp":result.config.timestamp,   //时间戳，自1970年以来的秒数
            "nonceStr":result.config.nonceStr,     //随机串
            "package":result.config.package,
            "signType":result.config.signType,     //微信签名方式：
            "paySign":result.config.paySign        //微信签名
          },
          function(res){
            console.log(res);
            if(res.err_msg == "get_brand_wcpay_request:ok") {
              Toast.success('支付成功');
              setTimeout(function () {
                that.$router.push({path:'/Member'});
              }, 1000);
              // 支付成功可以进行页面跳转
            }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
              Toast.fail('用户取消支付');
            }else{
              Toast.fail('支付失败');
            }
          }
        );
      },


      recordapi(){
          var that = this;
          var userid = that.$cookieStore.getCookie('userid');
          that.$api.post("/Index/memberkt",{'id':that.id}).then(res => {
            console.log(res);
            that.info = res.info;
            that.about = res.info.about;
          });
      },
    }
}
</script>
